using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InvestmentIntelligence.DbModel.Models.Mapping
{
    public class AnalysisGroupMap : EntityTypeConfiguration<AnalysisGroup>
    {
        public AnalysisGroupMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("AnalysisGroup", "iPerform");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");

            // Relationships
            this.HasMany(t => t.FundBookEntities)
                .WithMany(t => t.AnalysisGroups)
                .Map(m =>
                    {
                        m.ToTable("AnalysisGroup2FundBookEntity", "iPerform");
                        m.MapLeftKey("AnalysisGroupId");
                        m.MapRightKey("FundBookEntityId");
                    });

            this.HasMany(t => t.Users)
                .WithMany(t => t.AnalysisGroups)
                .Map(m =>
                    {
                        m.ToTable("AnalysisGroup2User", "iPerform");
                        m.MapLeftKey("AnalysisGroupId");
                        m.MapRightKey("UserId");
                    });


        }
    }
}
